	function showWord(){
		if($("#buttonSvrFile").val()=="显示正文"){
				$("#divTgContain").show();
				$("#wordBox").show();
				$("#divTgContain").contents().find("object").show();
				$("#buttonSvrFile").val("隐藏正文");
		}else{
			$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
		}
	}
	
	//function checkForm(){
	//    var strMsg = "";
		//类型：AlphaNumeric,Date,Email,Empty,Numeric,Money,PostalCode,Url
	//	if( strMsg != "" )
	//	{
	//		alert( strMsg );
	//		return false;
	//	}
	//	else	return true;
	//}

	$(function() {
		$("form").validationEngine({alertShow:true}); //表单验证
	});
	
	//表单提交
	function opt_submit(){
		if($("#isSeal").val()=="0"){
			if(!confirm("盖章尚未提交,是否继续保存？")){
				return ;
			}
		}
		docFileType="ZW";
		saveDocFile();
		$("form").eq(0).attr("action",actName + '!submitSave.shtml');
		$("form").eq(0).submit();
	}
	
	function opt_draftSave(){
	
		if($("#isSeal").val()=="0"){
			if(!confirm("盖章尚未提交,是否继续保存？")){
				return ;
			}
		}
		docFileType="ZW_DRAFT";
		saveDocFile();
		$("#isDraftSave").val('1');
		
		$("form").eq(0).attr("action",actName + '!draftSave.shtml');
		$("form").eq(0).submit();
	}
	//主办所有单位打开openReference
	function openPerAllMainUnit(){
	//	$("#buttonSvrFile").val("显示正文");
	//	$("#divTgContain").hide();
	//	$("#wordBox").hide();
	//	$("#divTgContain").contents().find("object").hide();
	
		var seleObjId ="swUnitTypeValue"
		var valueEleId = "weekRecord\\.swUnit\\.id";
		var titleEleId = "weekRecord\\.swUnit\\.name";
		seleObjId = seleObjId.replace(".","\\.");
		var type = $('#' + seleObjId).val();
		var rtn = valueEleId + '=value1&' + titleEleId + '=value2';
		
		//openReferenceM('SysDept', 'showEditDeptTreeAll', rtn);
			openReferenceM('sysOrg','getOrg',rtn);
	}
	
	function changeDate(date){
		if(date.value==3){
			$("#weekRecord\\.expectTime").val($("#nowDateAddThree").val())
		}else if(date.value==5){
			$("#weekRecord\\.expectTime").val($("#nowDateAddFive").val())
		}else if(date.value==7){
			$("#weekRecord\\.expectTime").val($("#nowDateAddSeven").val())
		}	
	}
	//原来的方法==========================================start


	/**
	 * 处理
	 */
	function opt_deal() {
			$.ajax({
			   type: 	"POST",
			   url: 	"wfEntityAction!getSwDefineInfos.shtml",
			   dataType:	"json",
			   async:false,
			   success: function(data){
			   $("#wfDefineInfoId").empty(); 
			  	 for(var i=0;i<data.length;i++){
				 	$("#wfDefineInfoId").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
				 }
				}
			});
			var wfEntityId=$("#weekRecord\\.wfEntityId").val();
			if(isEmpty($.trim(wfEntityId))){
				 // 弹出框显示转成新流程信息编辑页面
				artDialog({
				    title: '收文登记',
				    content: document.getElementById('optConvert'),
				    width:700,
				    lock:true,
				    padding:"0px 10px 5px 10px",
				    ok: function(){
				    		this.close();
					   		convertOk();
							
				    },
				    cancel:true
				});
			}else{
					alert("当前文件已转收文");
					return;
			}
	}
		
	function convertOk(){
		    if(isEmpty($("#wfDefineInfoId").val())){
		        alert("请选择需要使用的收文流程！");
		        return;
		    }
		    $.ajax({
			   type: 	"POST",
			   url: 	actName + "!swRegister.shtml",
			   data : 		{"wfDefineInfoId":$("#wfDefineInfoId").val(),"weekRecord.id":$("#weekRecord\\.id").val()},
			   dataType:	"json",
			   async:false,
			   success: function(data){
			   		if(typeof(data.fail)!="undefined"){
						alert("转收文时出错：" + data.fail);
						return;
					}
			   			var formAction=$("form").eq(0).attr("action");
			  		  var winName = getNewWinName();
				      $("form").eq(0).attr("action",'wfEntityAction!detail.shtml?wfEntity.id='+data.info).attr("target",winName);
				      $("#weekRecord\\.wfEntityId").val(data.info);
					  openNewWin("",null,null,winName);
					  $("form").eq(0).submit();
					  
					  //恢复原form的action值
				      $("form").eq(0).attr("action",formAction).attr("target","");
				}
			});
	}

	function opt_createWord(){
		var oldAction = $("form").eq(0).attr("action");
		document.forms[0].action='weekRecordAction!createWord.shtml';
		document.forms[0].submit();
		document.forms[0].action=oldAction;		
	}

	function openPer(){
	$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
		openReference('PermUserGroup','deptDocGroup','weekRecord.swUnit.id=value_id&weekRecord.swUnit.name=value_name&leafOnly=true');
	}
	function openPerAll(){
	$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
		openReference('sysOrg','orgTree','weekRecord.swUnit.id=value_id&weekRecord.swUnit.name=value_name&leafOnly=true');
	}
	function openCo(){
	$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
		openReferenceM('PermUserGroup','deptDocGroup','weekRecord.coOperationUnitIds=value_id&weekRecord.coOperationUnitNames=value_name&getSavedData=true');
	}
	function openCoAll(){
	$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
		openReferenceM('sysOrg','orgTree','weekRecord.coOperationUnitIds=value_id&weekRecord.coOperationUnitNames=value_name&getSavedData=true');
	}

	//分管领导
	function openFgLeader(){
	$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
		openReference('DeptDocForm','reviewTree','weekRecord.fgLeader.id=value_id&weekRecord.fgLeader.userName=value_name');
	}


	function checkForm(){
		    var strMsg = "";
		    var l = 0;
		    var l2 = 0;
			var l3 = 0;
		    if(typeof($("#weekRecord\\.title").val())=="string"){
		    	  l = $("#weekRecord\\.title").val().length;
		    }
		    if(typeof($("#weekRecord\\.returnRemark").val())=="string"){
		    	  l2 = $("#weekRecord\\.returnRemark").val().length;
		    }
		     if(typeof($("#weekRecord\\.remark").val())=="string"){
		    	  l3 = $("#weekRecord\\.remark").val().length;
		    }
			//类型：AlphaNumeric,Date,Email,Empty,Numeric,Money,PostalCode,Url
			strMsg = strMsg + Validate( "weekRecord.title", "标题","NotEmpty");
			strMsg = strMsg + Validate( "weekRecord.expectTime", "限时日期","NotEmpty");
			strMsg = strMsg + Validate( "weekRecord.swUnit.id", "主办单位","NotEmpty");
			
			if($("#weekRecord\\.formCode").val()=="zdbgy"&&$("#editState").val()=='modify'){
				strMsg = strMsg + Validate( "weekRecord.fgLeader.id", "分管领导","NotEmpty");
			}
			
			if(l>70){
				alert( "标题不能大于70个字符！");
				return false;
			}
			if(l2>1000){
				alert( "备注不能大于1000个字符！");
				return false;
			}
			if(l3>500){
				alert( "部门意见不能大于500个字符！");
				return false;
			}
			if( strMsg != "" )
			{
				alert( strMsg );
				return false;
			}
			else	{
			if($("#editState").val()=="modify"){				
				if($("#currentUser\\.orgName").val().toString().indexOf($("#weekRecord\\.swUnit\\.name").val().toString())!=-1){
					alert("发文单位与主办单位不能同一单位！");
					return false;
				}	
			}
			
			if($("#editState").val()=="modify"&&$("#weekRecord\\.formCode").val()=="zdyxq"){				
				if($("#weekRecord\\.swUnit\\.name").val()=="市人民政府办公室"){
					alert("发给市府办的事项,请使用最多半个月流程");
					return false;
				}	
			}
			if($("#editState").val()=="isOver"&&$("#weekRecord\\.formCode").val()=="zdyxq"){		
				if($("#weekRecord\\.agreeOpinion2").val()==""&&isNeedAssess==1){
					alert("投诉意见不能为空");
					return false;
				}	
			}	
				
			if($("#weekRecord\\.coOperationUnitIds").val().toString().indexOf($("#weekRecord\\.swUnit\\.id").val().toString())!=-1){
				alert("主办单位与协办单位重复！");
				return false;
			}
			return true;
			}
	}


		
	//显示隐藏
	var isHide=0;
	function opt_openAndHide(){
		if(isHide==0){
			$("#isOpen").show();
			isHide=1
		}else{
			$("#isOpen").hide();
			isHide=0
		}
	}
		
	//按选择的到期期限变换到期日期
	function timeLimitChange(obj){
		var date=new Date(Date.parse($("#curDate").val().replace(/-/g,"/")));
			if(1==$(obj).val()){
				date.setDate(date.getDate()+7);
				$("#weekRecord\\.expectTime").val(date.format("yyyy-MM-dd"));
			}else if(2==$(obj).val()){
				date.setMonth(date.getMonth()+1);
				$("#weekRecord\\.expectTime").val(date.format("yyyy-MM-dd"));
			}
			else if(3==$(obj).val()){
				$("#weekRecord\\.expectTime").val('2099-01-01');
			}
	}

	//新建的事项默认办理时限为7日，时间精确到分即可。默认紧急程度为常规。
	function opt_draft(){
	   if($("#isSeal").val()=="0"){
			if(!confirm("盖章尚未提交,是否继续保存？")){
				return ;
			}
		}
		docFileType="ZW_DRAFT";
		saveDocFile();
		$("#isDraftSave").val('1');
		opt_save();
	}

	//=====opt_isfinish==============
	function opt_isfinish(){
	//这段代码用于市府办 提交办结的
		if($("#isAllReadyDeal").val()==1&&$("#entityTitle").val()=="最多半个月"){
			alert("该事项已转收文,无法办结");
			return false;
		}	
	    var strMsg = "";	
		if(window.confirm('确定要提交该事项吗？')){
			//类型：AlphaNumeric,Date,Email,Empty,Numeric,Money,PostalCode,Url
			strMsg = strMsg + Validate( "weekRecord.title", "标题","NotEmpty");
			strMsg = strMsg + Validate( "weekRecord.expectTime", "限时日期","NotEmpty");
			strMsg = strMsg + Validate( "weekRecord.swUnit.id", "主办单位","NotEmpty");
			strMsg = strMsg + Validate( "weekRecord.returnRemark", "主办单位意见","NotEmpty");
			if( strMsg != "" ){
				alert( strMsg );
				return false;
			}else{
				$("form").eq(0).attr("action",actName + '!isfinish.shtml');
				$("form").eq(0).submit();
				}
	           return true;
	        }else{
	                 return false;
	             }									
	}
		
	function opt_agree(){
			if(window.confirm('确定要完结该事项吗？')){
			//重置意见
			$("#newAgreeOpinion").val("");
			
					if($("#entityTitle").val()=="最多一星期"){
						if(window.confirm('是否直接进行完结评价？')){
						//给一个默认的值,不然第一次进去的时候,拿不到满意显示没有评价
						$("#newAgreeOpinion").val("0");
						artDialog({
					      	title: '办结评价',
					      	content: document.getElementById('agreeOpinionid2'),
					      	width:'50%',
					      	height:'50%',
					      	lock: '提交',
							zIndex:9999,
							okVal:"提交",
					      	ok: function(){
					      	
					      	//如果是投诉,投诉意见不能为空
						      	if($("#newAgreeOpinion").val()==3){
						      		$("#newAssessOpinion").val($("#newAssessOpinion2").val());					      			
					      			if($("#newAssessOpinion").val()==""){
					      				alert("投诉意见不能为空")
					      				return false;	
					      			}					      					      			
						      	}				      				      	
						      	$("form").eq(0).attr("action",actName + '!agree.shtml');
								$("form").eq(0).submit();					      	
					      	},
					      	cancel: true
					      });
						}else {
							//直接提交		
	        		 	$("form").eq(0).attr("action",actName + '!agree.shtml');
						$("form").eq(0).submit();					
						}
						cancel: true	
					}else {
						//最多半个月不需要评价			
	        		 	$("form").eq(0).attr("action",actName + '!agree.shtml');
						$("form").eq(0).submit();	
					}
					cancel: true
	             return true;
	          }else{
	         	 cancel: true
	             return false;
	         }
	}
		
	function opt_assess(){
			if($("#isHasAssess").val()==1){
				alert("该事项已经进行过完结评价");
				return false;	
			}
			if($("#newAgreeOpinion").val()==""){
			//如果为空 需要给个初始值
				$("#newAgreeOpinion").val("0");
			}	
			if(window.confirm('确定评价该事项吗？')){
	            	 	$("form").eq(0).attr("action",actName + '!agreeAssess.shtml');
						$("form").eq(0).submit();		
	                 return true;
	              }else{
	                 return false;
	             }
	}
		
	function opt_recovery(){
		if(window.confirm('确定要回收该事项吗？')){
		//回收不需要验证分管领导
	            $("#clickId").val($("#weekRecord\\.id").val());               
	        	 	$("form").eq(0).attr("action",actName + '!recovery.shtml');
					$("form").eq(0).submit();		
	             return true;
	          }else{
	             return false;
	         }		
	}

	function opt_lwRecovery(){
		if(window.confirm('确定要回收该事项吗？')){
	            $("#clickId").val($("#weekRecord\\.id").val());               
	        	 	$("form").eq(0).attr("action",actName + '!lwRecovery.shtml');
					$("form").eq(0).submit();		
	             return true;
	          }else{
	             return false;
	         }		
	}	
		
	function opt_xbIsfinish(){
		if(window.confirm('确定提交协办意见？')){
	            $("#clickId").val($("#weekRecord\\.id").val());               
	        	 	$("form").eq(0).attr("action",actName + '!xbIsfinish.shtml');
					$("form").eq(0).submit();		
	             return true;
	          }else{
	             //alert("取消");
	             return false;
	         }		
	}	
	//============end================
		
	function ajaxSave(){
	  var param=new Array();
		param.push("applyType="+$("#weekReview\\.applyType").val());
		param.push("recordId="+$("#weekRecord\\.id").val());
		$("#buttonSvrFile").val("显示正文");
		$("#divTgContain").hide();
		$("#wordBox").hide();
		$("#divTgContain").contents().find("object").hide();
		artDialog.open(encodeURI("weekReviewAction!toReviewApply.shtml?"+param.join("&")),{
					title:	"申请审核",
					lock:	true,
					width: "60%",
					height: "60%",
					zIndex:9999,
					okVal:"提交",
					ok:		function(){
							var $obj = $(this.iframe.contentWindow.document);
							var formdata = $obj.find("form").serializeArray();
							var d = {};
							$.each(formdata, function() {
						       d[this.name] = this.value;
						    });
							var check = checkApplyForm($obj);
							if(!check){
								return false;
							}
							var isRight = true;
							// 保存数据
							$.ajax({
								type : 		"POST",
								url : 		"weekReviewAction!ajaxSave.shtml",
								data : 		formdata,
								//dataType: 	"json",
								success : function(data) {
									if(typeof(data.fail)!="undefined"){
										var message = "申请提交失败:" + data.fail;
										artDialog({
										    title: '申请审核',
										    content: message,
										    lock: true,
										    ok: function(){
										    },
										   cancel:false
										});
										isRight = false;
										return false;
									}else{
										var message ="提交成功！";
										artDialog({
										    title: '申请审核',
										    content: message,
										    lock: true,
										    ok: function(){
										    	if($("#isFromSysPendings").val()=="1"){
												window.close();
												}else{
													window.location.href="weekRecordAction!list.shtml?statusType=3&editState=newdb";
												}
										    },
										   cancel:false
										});
										
									
									}
								},
								error : function() {
									isRight = false;
									var message ="申请提交失败!";
									artDialog({
										    title: '申请审核',
										    content: message,
										    lock: true,
										    ok: function(){
										    },
										  cancel:false
										});
								}
							});
						return isRight;					},
					cancel:	true
				});
	}
		
	function opt_later(){
		$("#weekReview\\.applyType").val("1");
		$.ajax({
		   type: 	"POST",
		   url: 	"weekReviewAction!preReview.shtml",
		   data: 	{"weekFormId":$("#weekRecord\\.id").val(),"applyType":"1","fromType":"1"},	
		   dataType:	"json",
		   success: function(data){
				if(typeof(data.fail)!="undefined"){
					openArgDialog('审核',data.fail);
					return;
				}
				ajaxSave();
		     }
		});
	}

	function opt_refuse(){
		$("#weekReview\\.applyType").val("2");
		$.ajax({
		   type: 	"POST",
		   url: 	"weekReviewAction!preReview.shtml",
		   data: 	{"weekFormId":$("#weekRecord\\.id").val(),"applyType":"2","fromType":"1"},	
		   dataType:	"json",
		   success: function(data){
				if(typeof(data.fail)!="undefined"){
					openArgDialog('审核',data.fail);
					return;
				}
				ajaxSave();
		     }
		});
	}

	function opt_again(){
		$("#weekReview\\.applyType").val("3");
		$.ajax({
		   type: 	"POST",
		   url: 	"weekReviewAction!preReview.shtml",
		   data: 	{"weekFormId":$("#weekRecord\\.id").val(),"applyType":"3","fromType":"1"},	
		   dataType:	"json",
		   success: function(data){
				if(typeof(data.fail)!="undefined"){
					openArgDialog('审核',data.fail);
					return;
				}
				ajaxSave();
		     }
		});
	}
		
	function opt_save1(){
		if($("#isSeal").val()=="0"){
			if(!confirm("盖章尚未提交,是否继续提交？")){
				return ;
			}
		}
		//发送ajax 判断提交时间,是否超过预期时间	
		$.ajax({
			   type: 	"POST",
			   url: 	"weekRecordAction!ajaxIsOutTime.shtml",
			   data : 		{"sendExpectDate":$("#weekRecord\\.expectTime").val(),"sendFormCode":$("#weekRecord\\.formCode").val()},
			   dataType:	"json",
			   async:false,
			   success: function(data){
				   	if(data.success=="success"){
					  	$("#isDraftSave").val("");
						docFileType="ZW";
						saveDocFile();
						opt_save();	
			  	 	}else{
			  	 	alert(data.fail)
			  	 	}					
				}	
			});

	}
		
	//改变办理办理时限
	function changeExpectDate(){
	//暂时不用了 这个方法
//		if($("#weekRecord\\.swUnit\\.name").val()=='市人民政府办公室'){
//			$("#weekRecord\\.expectTime").val($("#nowDateAddFifteen").val())
//		}else{
//			$("#weekRecord\\.expectTime").val($("#nowDateAddSeven").val())
//		}
	}
		
//	function changeDate(date){
//		if(date.value==3){
//			$("#weekRecord\\.expectTime").val($("#nowDateAddThree").val())
//		}else if(date.value==5){
//			$("#weekRecord\\.expectTime").val($("#nowDateAddFive").val())
//		}else if(date.value==7){
//			$("#weekRecord\\.expectTime").val($("#nowDateAddSeven").val())
//		}	
//	}
		
	function changeDateCunstom(){
		$("input[name=timeLimit]:eq(3)").attr("checked",'checked');
	}
		
		
		
	var isNeedAssess=0
	function changeAssess(date){
		if(date.value==3){
			isNeedAssess=1
			$("#newAgreeOpinion").val("3");
			$("#userForAssess").show(); 
		}else if(date.value==2){
			$("#newAgreeOpinion").val("2");
			isNeedAssess=0
			$("#userForAssess").hide();	
		}else if(date.value==1){
			$("#newAgreeOpinion").val("1");
			isNeedAssess=0
			$("#userForAssess").hide();	
		}else if(date.value==0){
			$("#newAgreeOpinion").val("0");
			isNeedAssess=0
			$("#userForAssess").hide();	
		}else{
			isNeedAssess=0
			$("#userForAssess").hide();
		}
	}
		
	$(function (){
		if($("#timeSelect").val()==3){
			$("#timeLimit_0").attr("checked","true");	
		}else if($("#timeSelect").val()==5){
			$("#timeLimit_1").attr("checked","true");
		}else if($("#timeSelect").val()==7){
			$("#timeLimit_2").attr("checked","true");
		}else{
			$("#timeLimit_3").attr("checked","true");		
		}					
	});	

	//============str
	function opt_directReturn(){
		if($("#isAllReadyDeal").val()==1){
			alert("该事项已转收文,无法退回");
			return false;		
		}
		if($("#isHasReviewStatus").val()=="0"&&$("#isHasReviewType").val()=="延期审核"){
			alert("存在未办理的延期审核,无法退回");
			return false;		
		}else if($("#isHasReviewStatus").val()=="0"&&$("#isHasReviewType").val()=="不同意件审核"){
			alert("存在未办理的不同意件审核,无法退回");
			return false;
		}
		if(window.confirm('是否直接退回该事项')){
					artDialog({
					      	title: '退回原因',
					      	content: document.getElementById('returnOpinion'),
					      	width:'50%',
					      	height:'50%',
					      	lock: '提交',
							zIndex:9999,
							okVal:"提交",
					      	ok: function(){							      	
					      	$("#newReturnOpinion").val($("#weekRecord\\.returnOpinion").val());	      	
	           				$("#clickId").val($("#weekRecord\\.id").val());               
	        	 			$("form").eq(0).attr("action",actName + '!directReturn.shtml');
							$("form").eq(0).submit();					      	
					      	},
					      	cancel: true
					      });

	             return true;
	          }else{
	             return false;
	         }									
	}
	//============end
		
	function changeReturnOpinion(date){
		$("#weekRecord\\.returnOpinion").val(date.value);
	}
		
	function opt_applyReturn(){
		if(window.confirm('是否申请退回该事项')){
	            $("#clickId").val($("#weekRecord\\.id").val());               
	        	 	$("form").eq(0).attr("action",actName + '!applyReturn.shtml');
					$("form").eq(0).submit();		
	             return true;
	          }else{
	             return false;
	         }		
	}

		
		
	//主办常用单位打开
	function opt_openMainUnit(){
		$("#forShowMainUserName").val($("#weekRecord\\.swUnit\\.name").val())
		$("#forShowMainUserId").val($("#weekRecord\\.swUnit\\.id").val())
		mainUnitId="zb_"+$("#weekRecord\\.swUnit\\.id").val();
		$("#"+mainUnitId).css('color','red');	
		artDialog({
				id:'mainUnitId',
		      	title: '常用单位',
		      	content: document.getElementById('openMainUnit'),
		      	width:'70%',
		      	height:'70%',
		      	lock: true,
		      	ok: function(){
		      		$("#weekRecord\\.swUnit\\.name").val($("#forShowMainUserName").val());
		      		$("#weekRecord\\.swUnit\\.id").val($("#forShowMainUserId").val());
		      	},
		      	cancel: false
		      });

	}
		
	var mainUnitId ;
	//主办常用单位单击事件
	function onclickOpenMainUnit(date){
		$("#"+mainUnitId).css('color','black')
		//用于记录上一个ID 
		mainUnitId = date.id;	
		$(date).css('color','red') 
		$("#forShowMainUserName").val(date.title)
		$("#forShowMainUserId").val(date.id.replace(/zb\_/g,""))
	}
		
	//主办常用单位双击事件
	function dbclickOpenMainUnit(){
//		alert("11");
		$("#weekRecord\\.swUnit\\.name").val($("#forShowMainUserName").val());
		$("#weekRecord\\.swUnit\\.id").val($("#forShowMainUserId").val());
		artDialog({id:"mainUnitId"}).close();

	}
		
	//主办所有单位打开openReference
//	function openPerAllMainUnit(){
//		$("#buttonSvrFile").val("显示正文");
//		$("#divTgContain").hide();
//		$("#wordBox").hide();
//		$("#divTgContain").contents().find("object").hide();
//		openReference('sysOrg','orgTree','forShowMainUserId=value_id&forShowMainUserName=value_name&leafOnly=true');
//	}

		
	//获取ids names 并且标红
	function opt_setCoUnitIdsAndcoUnitNames(){	
		if($("#weekRecord\\.coOperationUnitIds").val()!=""){
			coUnitIds="xb_"+$("#weekRecord\\.coOperationUnitIds").val();
			coUnitIds=coUnitIds.replace(/\,/g,",xb_");
			coUnitNames=$("#weekRecord\\.coOperationUnitNames").val();
			var arrCoUnitIds = coUnitIds.split(",");
				for(var i = 0;i<arrCoUnitIds.length;i++){
					//标红
					coUnitNum=i+1;
					$("#"+arrCoUnitIds[i]).css('color','red');
				}	
		}		
	}

	//协办常用单位
	function opt_openCoUnit(){	
			$("#forShowCoUserNames").val($("#weekRecord\\.coOperationUnitNames").val());
			$("#forShowCoUserIds").val($("#weekRecord\\.coOperationUnitIds").val());
			opt_setCoUnitIdsAndcoUnitNames();
			artDialog({
					id:'coUnitId',
			      	title: '常用单位',
			      	content: document.getElementById('openCoUnit'),
			      	width:'70%',
			      	height:'70%',
			      	lock: true,
			      	ok: function(){
			      		$("#weekRecord\\.coOperationUnitNames").val($("#forShowCoUserNames").val());
			      		$("#weekRecord\\.coOperationUnitIds").val($("#forShowCoUserIds").val());
			      	},
			      	cancel: false
			      });
	}
		
	//协办常用单位单击事件
	var coUnitNum=0;
	var coUnitIds;
	var coUnitNames;
		
	//这2个值需赋值(打开协办多选的时候赋值,用于草稿)
	function onclickOpenCoUnit(date){
			//alert(coUnitIds);
			//判断如果coUnitNum=0,点击为增加颜色变红
			if(coUnitNum==0){
				coUnitIds=date.id
				coUnitNames=date.title
				$(date).css('color','red')
				coUnitNum=1;	
			}else if(coUnitNum>0){
				//判断是否已经存在 coUnitIds.indexOf(date.id)=0表示第一个
				if(coUnitIds.indexOf(date.id) == -1){
					coUnitIds=coUnitIds+","+date.id
					coUnitNames=coUnitNames+","+date.title
					$(date).css('color','red')
					coUnitNum=coUnitNum+1;
				}else{
					//判断是否是第一个
					$(date).css('color','black')
					if(coUnitIds.indexOf(date.id) == 0){
						//判断是否唯一一个
						if(coUnitIds.indexOf("\,") == -1){
							coUnitIds=coUnitIds.replace(date.id,"");
							coUnitNames=coUnitNames.replace(date.title,"");
							coUnitNum=coUnitNum-1;
						}else {
							coUnitIds=coUnitIds.replace(date.id+",","");
							coUnitNames=coUnitNames.replace(date.title+",","");
							coUnitNum=coUnitNum-1;
						}
						
					}else{
						coUnitIds=coUnitIds.replace(","+date.id,"");
						coUnitNames=coUnitNames.replace(","+date.title,"");
						coUnitNum=coUnitNum-1;
					}				
				}
			}
		
			//赋值给forShowCoUserNames,forShowCoUserIds
			$("#forShowCoUserNames").val(coUnitNames);
			if(coUnitNum>1){
				var fsIds = coUnitIds.replace(/xb\_/g,"");
				$("#forShowCoUserIds").val(fsIds);
			}else{	
				var fsIds = coUnitIds.replace(/xb\_/g,"");
				$("#forShowCoUserIds").val(fsIds);
			}
	}
		
	var oldCoUnitIds
		
	function openPerAllCoUnit(){
			oldCoUnitIds=coUnitIds//用于取消标红
			$("#buttonSvrFile").val("显示正文");
			$("#divTgContain").hide();
			$("#wordBox").hide();
			$("#divTgContain").contents().find("object").hide();
			openReferenceM('sysOrg','orgTree','forShowCoUserIds=value_id&forShowCoUserNames=value_name&getSavedData=true');
	}
		
	function onchangeforShowCoUserIds(date){
		
		if(oldCoUnitIds==""){	
		}else{
			var arrOldCoUnitIds=oldCoUnitIds.split(",");
			for(var i=0;i<arrOldCoUnitIds.length;i++){
				$("#"+arrOldCoUnitIds[i]).css('color','black');
			}			
		}	
		if(date.value==""){			
		}else{
			var newDate = date.value.split(",");
			for(var i=0;i<newDate.length;i++){
				$("#xb_"+newDate[i]).css('color','red');
			}
		}		
			coUnitIds="xb_"+$("#forShowCoUserIds").val();
			coUnitIds=coUnitIds.replace(/\,/g,",xb_");
			coUnitNames=$("#forShowCoUserNames").val();
	}

		
	function onchangeforShowCoUserNames(date){
		coUnitNames=date.value;
	}

	//修改分管领导
	//function opt_changeFgLeader(){	
		//openReference('WeekRecord','fgLeader','weekRecord.swLeader.id=value1&weekRecord.swLeader.userName=value2&inParams=${(fgLeaderIds)?if_exists}');
	//}


	function onchangeFgLeader(date){
		//发送ajax 修改分管领导
		var newLeaderId = date.value
		var theRecordId = $("#weekRecord\\.id").val();
		$.ajax({
			   type: 	"POST",
			   url: 	"weekRecordAction!ajaxChangeFgLeader.shtml",
			   data : 		{"newLeaderId":newLeaderId,"theRecordId":theRecordId},
			   dataType:	"json",
			   async:false,
			   success: function(data){
				   	if(data.success=="success"){
						opt_list();
			  	 	}else{
			  	 	    alert(data.fail)
			  	 	}					
				}	
			});
	}
	
	/**
	 * 审核表单校验
	 * @param obj
	 * @returns
	 */
	function checkApplyForm($obj){
	    var l = 0;
	    if(typeof($obj.find("#weekReview\\.applyReason").eq(0).val())=="string"){
	    	  l = $obj.find("#weekReview\\.applyReason").eq(0).val().length;
	    }
	    if(l>500){
	    	alert("申请理由不能超过500个字符！");
	    	return false;
	    }
	    if(l==0){
	    	alert("申请理由不能为空");
	    	return false;
	    }
	    var applyType = $obj.find("#weekReview\\.applyType").eq(0).val();
	    if(applyType==1){
	    	if($obj.find("#weekReview\\.delayDate").eq(0).val()=="" || $obj.find("#weekReview\\.delayDate").eq(0).val() == null){
		    	alert("申请延期时间不能为空");
		    	return false;
		    }
	    }
	    var reviewBy = $obj.find("#weekReview\\.reviewBy\\.id").eq(0).val();
	    if(reviewBy==null || reviewBy=="" || typeof reviewBy== "undefined"){
	    	alert("审核人不能为空");
	    	return false;
	    }
		return true;
	}
	
	
	function openArgDialog(title,message){
		if(title==null || title==""){
			title = "提示";
		}
		if(message==null || message==""){
			message = "错误";
		}
		artDialog({
		    title: title,
		    content: message,
		    lock: true,
		    ok: function(){
		    },
		    cancel:false
		});
	}
	